package com.delu.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

@EnableWebSocket
@Slf4j
@Configuration
public class MyWebSocketConfig implements WebSocketConfigurer {

    @Autowired
    private MyHandshakeInterceptor handshakeInterceptor;

    @Autowired
    private MySocketHander socketHander;

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {

        //部分 支持websocket 的访问链接,允许跨域
        registry.addHandler(socketHander, "/my_SXD_Socket").addInterceptors(handshakeInterceptor).setAllowedOrigins("*");
        //部分 不支持websocket的访问链接,允许跨域
        registry.addHandler(socketHander, "/sockjs/my_SXD_Socket").addInterceptors(handshakeInterceptor).setAllowedOrigins("*").withSockJS();

    }
}